<!DOCTYPE html>
<html>

	<head>
		<meta charset="utf-8" />
		<title></title>
		<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no">
		<link rel="stylesheet" href="css/amazeui.min.css" tppabs="http://yanshi.sucaihuo.com/modals/16/1608/demo/css/amazeui.min.css" type="text/css" />
		<link rel="stylesheet" href="css/style.css" tppabs="http://yanshi.sucaihuo.com/modals/16/1608/demo/css/style.css" type="text/css" />
		<link rel="stylesheet" href="layui/css/layui.css" tppabs="http://yanshi.sucaihuo.com/modals/16/1608/demo/css/style.css" type="text/css" />
		<style>
			/*修改提示文字的颜色*/
			
			input::-webkit-input-placeholder {
				/* WebKit browsers */
				color: #bebebe;
			}
			
			input:-moz-placeholder {
				/* Mozilla Firefox 4 to 18 */
				color: #bebebe;
			}
			
			input::-moz-placeholder {
				/* Mozilla Firefox 19+ */
				color: #bebebe;
			}
			
			input:-ms-input-placeholder {
				/* Internet Explorer 10+ */
				color: #bebebe;
			}
		</style>
	</head>

	<body>
		<header data-am-widget="header" class="am-header am-header-default jz">
			<div class="am-header-left am-header-nav">
				<a href="javascript:history.back()" class="">
					<i class="am-icon-chevron-left"></i>
				</a>
			</div>
			<h1 class="am-header-title">
		          <a href="#title-link" class="">我的资料</a>
		      </h1>
		</header>
		<div class="logo"><img id="myimg" src="images/tx.png" style="width:100px;height:100px;border-radius: 100%;" /></div>
		<div class="logotext">
			<p>点击头像修改</p>
		</div>
		<div class="about">
			<form id="infos">
				<input type="hidden" name="id" id="id" />
				<div class="wxdy">
					<span>酒店简称</span>
					<em><input style="padding-left: 20px;font-size: 14px;color: #bebebe;width:140%;" id="jc" name="hotelSinName"></em>
				</div>
				<div class="wxdy">
					<span>酒店全称</span>
					<em><input style="padding-left: 20px;font-size: 14px;color: #bebebe;width:140%;"  id="qc" name="hotelName"/></em>
				</div>
				<div class="wxdy">
					<span>负&nbsp;&nbsp;责&nbsp;&nbsp;人</span>
					<em><input style="padding-left: 20px;font-size: 14px;color: #bebebe;width:140%;"  id="fzr" name="name"></em>
				</div>
				<div class="wxdy">
					<span>酒店热线</span>
					<em><input style="padding-left: 20px;font-size: 14px;color: #bebebe;width:140%;"  id="rx" name="tel"></em>
				</div>
				<div class="wxdy">
					<span>联系方式</span>
					<em><input style="padding-left: 20px;font-size: 14px;color: #bebebe;width:140%;"  id="lxfs" name="phone"></em>
				</div>
				<div class="intro">
					<textarea id="bz" style="width: 100%;height: 100px;border: none;" name="remark"></textarea>
				</div>
			</form>
		</div>
		<input type="button" value="修改资料" class="money-btn">
		<div style="height: 55px;"></div>
		<input type="hidden" id="imgs">
		<!--<input type="file" name="file" style="display: none" id="file" onchange="getImg();" accept="image/*;capture=camera"/>-->
	</body>
	<script type="text/javascript" src="js/jquery.min.js" tppabs="http://yanshi.sucaihuo.com/modals/16/1608/demo/js/jquery.min.js"></script>
	<script type="text/javascript" src="js/ajaxfileupload.js"></script>
	<script type="text/javascript" src="js/amazeui.min.js" tppabs="http://yanshi.sucaihuo.com/modals/16/1608/demo/js/amazeui.min.js"></script>
	<script type="text/javascript" src="js/hui.js"></script>
	<script src="layui/layui.js" charset="utf-8"></script>
	<!-- 注意：如果你直接复制所有代码到本地，上述js路径需要改成你本地的 -->
	<script>
		var id = localStorage.getItem("id");
		if(!id) {
			location.href = "login.html";
		} else {
			refush(id);
		}

		function getImg() {
			hui.postJSON(
				rootpath + '/businessMan/updateImg', {
					id: id,
					files: $("#imgs").val()
				},
				function(msg) {
					hui.toast('修改成功', 1000);
				},
				function(e) {
					hui.iconToast('读取消息失败', 'warn');
					console.log(e);
				}
			);
		}

		function refush(id) {
			hui.getJSON(
				rootpath + '/businessMan/findBusinessMan/' + id,
				function(msg) {
					console.log(msg);
					if(msg.isActive!=0){
						hui.toast('你已被管理员禁用，将无权限访问!', 'warn');
						location.href="login.html";
						return;
					}
					$("#id").val(msg.id);
					//$("#myname").html(msg.hotelSinName);
					//$("#name").html(msg.name);
					$("#jc").val(msg.hotelSinName);
					$("#qc").val(msg.hotelName);
					$("#fzr").val(msg.name);
					$("#lxfs").val(msg.phone);
					$("#bz").val(msg.remark);
					$("#rx").val(msg.tel);
					if(msg.faceImg) {
						if(msg.faceImg.indexOf("http") > -1) {
							document.getElementById("myimg").src = msg.faceImg;
						} else {
							document.getElementById("myimg").src = rootpath + "/" + msg.faceImg;
						}
					}
				},
				function(e) {
					hui.iconToast('读取消息失败', 'warn');
					console.log(e);
				}
			);
		}
		$(".money-btn").click(function() {
			var id = $("#id").val();
			var hotelSinName = $("#jc").val();
			var hotelName = $("#qc").val();
			var name = $("#fzr").val();
			var tel = $("#rx").val();
			var phone = $("#lxfs").val();
			var remark = $("#bz").val();
			if(!hotelSinName) {
				hui.toast('酒店简称不能为空', 1000);
				return;
			}
			if(hotelSinName.length > 6) {
				hui.toast('酒店简称长度不能超过六个字符', 1000);
				return;
			}
			if(!tel) {
				hui.toast('酒店热线不能为空', 1000);
				return;
			}
			if(tel.length > 20) {
				hui.toast('酒店热线长度不能超过二十个字符', 1000);
				return;
			}
			if(!phone) {
				hui.toast('手机号不能为空', 1000);
				return;
			}
			if(phone) {
				if(phone.length != 11) {
					hui.toast('联系方式输入有误', 1000);
					return;
				}
			}
			if(name) {
				if(name.length > 20) {
					hui.toast('负责人长度不能超过二十个字符', 1000);
					return;
				}
			}
			hui.postJSON(
				rootpath + '/businessMan/businessManUpdateSave', {
					id: id,
					hotelSinName: hotelSinName,
					hotelName: hotelName,
					name: name,
					tel: tel,
					phone: phone,
					remark: remark

				},
				function(msg) {
					hui.confirm(msg.message+'是否回到我的主页？', ['取消','确定'], function(){
				        location.href="main.html";
				    },function(){
				    	hui.toast(msg.message, 1000);
				    });
					
				},
				function(e) {
					hui.iconToast('读取消息失败', 'warn');
					console.log(e);
				}
			);
		});
		layui.use('upload', function() {
			var $ = layui.jquery,
				upload = layui.upload;
			//普通图片上传
			var uploadInst = upload.render({
				elem: '#myimg',
				url: rootpath+'/file/up',
				before: function(obj) {
					//预读本地文件示例，不支持ie8
					obj.preview(function(index, file, result) {
						$('#myimg').attr('src', result); //图片链接（base64）
					});
				},
				done: function(res) {
					//如果上传失败
					if(res.code > 0) {
						hui.toast('修改失败，服务器繁忙', 1000);
					} else {
						$("#imgs").val(res.data.src);
						getImg();
					}
					//上传成功
				},
				error: function() {
					//演示失败状态，并实现重传
					var demoText = $('#demoText');
					demoText.html('<span style="color: #FF5722;">上传失败</span> <a class="layui-btn layui-btn-mini demo-reload">重试</a>');
					demoText.find('.demo-reload').on('click', function() {
						uploadInst.upload();
					});
				}
			});
		});
	</script>

</html>